/**************************************************************************
SOCIAL TIES IN ACADEMIA: SOCIAL TIES IN ACADEMIA
by Tommaso Colussi
do file: Table 1
**************************************************************************/
cd ${Dir}
do MASTER.do
set more off
/***********************************************************************
Table 1: Articles' characteristics
		a) define connected articles if a tie exists with at least one editor 
		and the editor is in charge
		c) compute own-journal references
		d) descriptive stats on main outcomes
		e) tabulate on JEL codes at three-digit
		f) HHI Index
************************************************************************/
use "${DirALL}FINAL_SAMPLE.dta",clear

*a)
foreach x of varlist Tconn_*  refedit{
replace `x'=0 if `x'==.
replace `x'=0 if incharge==0
bys articlet: egen tie_`x'=max(`x')
}

label var Tconn_author "co-authorship tie (max) "
label var Tconn_ever "same faculty tie (max)"
label var Tconn_advisor "phd advisor tie (max)"
label var Tconn_phd "same phd tie (max)"
label var Tconn_pool "pooled tie (max)"
bys articletitle: keep if _n==1
drop name

*b)
split references , p(";")
expand 177
gen quote=""
bys articletitle: gen vv=_n
forvalues i=1(1)177{
set more off
bys articletitle: replace quote=references`i' if vv==`i'
}
drop vv references1-references177
gen gg=(quote!="")

gen quote_QJE=(strpos(quote,"Q J ECON"))
gen quote_AER=(strpos(quote,"AM ECON REV"))
gen quote_JPE=(strpos(quote,"J POLIT ECON"))
gen quote_ECA=(strpos(quote,"ECONOMETRICA"))
foreach var of varlist quote_*{
set more off
replace `var'=1 if `var'!=0
}
foreach var of varlist quote_*{
set more off
bys articletit: egen sum_`var'=sum(`var')
drop `var'
}
bys articletit: keep if _n==1

gen share_ownquote=.
levelsof journal, local(levels)
foreach l of local levels{
replace share_ownquote=sum_quote_`l'/n_references if journal=="`l'"
}
replace share_ownquote=0 if share_ownquote==.
sum share_ownquote

gen ownquote=.
levelsof journal, local(levels)
 foreach l of local levels{
replace ownquote=sum_quote_`l' if journal=="`l'"
}

*c)
gen n_pages= last_page-first_page
foreach var of varlist tie_Tconn_* tie_ref share_ownquote{
replace `var'=`var'*100
}
format citation8 n_pages tie_* n_references n_pages n_authors  share_ownquote ownquote %9.2f


*TABLE 
tab journal
tab journal if n_authors==1 
tabstat n_pages citation8 tie_* n_references n_pages n_authors  share_ownquote , by(journal) format stats(mean sd) columns(stats)  longstub


*d)
expand 7
gen jelcodes=""
bys articlet: g hh=_n
forvalues i=1(1)7{
replace jelcodes=article_jel`i' if hh==`i'
}

gen JEL = substr(jelcodes, 1, 1)
bys articlet JEL: gen vv=_n
replace JEL="" if vv>1

*TABLE
tab JEL if vv==1
bys journal: tab JEL if vv==1

*e)
use "${DirALL}ARTICLES.dta", clear
merge m:1 author year  using "${DirALL}AUTHORS.dta"
keep if _m==3 /*_m=1 unknwon, _m=2 missing years*/
drop _m

bys journal: egen den=count(author)
bys journal faculty_a: egen num=count(author)
bys journal faculty_a: gen share=(num/den)^2
bys journal faculty_a: keep if _n==1

collapse (sum) share, by(journal)
*TABLE
tab journal, su(share) mean

